package com.maple.common.jiabo;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;

import java.util.HashMap;

public class Utils {

    /// ==========佳博============
    /**
     * 检查USB设备的PID与VID
     * @param dev
     * @return
     */
    public static boolean checkUsbDevicePidVid(UsbDevice dev) {
        int pid = dev.getProductId();
        int vid = dev.getVendorId();
        return ((vid == 34918 && pid == 256) || (vid == 1137 && pid == 85)
                || (vid == 6790 && pid == 30084)
                || (vid == 26728 && pid == 256) || (vid == 26728 && pid == 512)
                || (vid == 26728 && pid == 256) || (vid == 26728 && pid == 768)
                || (vid == 26728 && pid == 1024) || (vid == 26728 && pid == 1280)
                || (vid == 26728 && pid == 1536));
    }

    public static boolean checkUsbDevicePidVid20(UsbDevice dev) {
        int pid = dev.getProductId();
        int vid = dev.getVendorId();
        return (vid == 0x483 && pid == 0x5741);
    }

    /**
     * 通过USB名称获取设备
     * @param context
     * @param usbName
     * @return
     */
    public static UsbDevice getUsbDeviceFromName(Context context, String usbName) {
        UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
        HashMap<String, UsbDevice> usbDeviceList = usbManager.getDeviceList();
        return usbDeviceList.get(usbName);
    }
}
